﻿@using CoralNode.Core.Entity.Domains.User
@using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Helper
@using Coralcode.Utils.Basic
@model CoralNode.Core.Entity.Domains.User.UserDomain

@{
    ViewBag.Title = "Edit";
}
@Html.IncludePage("CoralAdmin/user", "_Left")
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">用户管理&nbsp;&nbsp;/&nbsp;&nbsp;<b
                class=" t_small f_no">添加用户</b></span>
        </div>
        <div id="main">
            <div class="local">
                <a href="/m/user" class="ico ico_back btn"></a>
            </div>
            <div class="content_tab extra_normal">
                <div class="tablist extra_normal" data-js="tab">
                    <a href="#">主要信息</a>
                    <a href="#">详细信息</a>
                     @foreach (var group in ViewBag.ExtendGroupList)
                     {
                        <a href="#">@group.Title</a>
                    }
                </div>
            </div>
            <form id="spform" action="/m/user/editUser/@Model.Id" method="post" enctype="multipart/form-data">
                @if (@ViewBag.Msg != null)
                {
                    <div class="error_msg">
                        @ViewBag.Msg.Msg
                    </div>
                }
                <div class="pt_3 js_tabcnt">
                    <div class="table_form form_main ">
                        <div class="pl_2 pb_3">
                            @Html.AntiForgeryToken()
                            @Html.ValidationSummary(true)
                            <table>
                                <tbody>
                                    <tr>
                                        <th width="60">账号<span class="rq">*</span></th>
                                        <td>
                                            @Html.TextBoxFor(m => m.Account, new { @class = "text w_37 required" })
                                            @Html.HiddenFor(m => m.Id)
                                            <div class="exp ml_1">4-16个字符，支持英文小写、数字、下划线</div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th width="60">名称<span class="rq">*</span></th>
                                        <td>
                                            @Html.TextBoxFor(m => m.Name, new { @class = "text w_37 required" })
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="table_form form_main ">
                        <div class="pl_2 pb_3">
                            <table data-js="tabCnt">
                                <tbody>
                                    <tr>
                                        <th width="60">地区</th>
                                        <td>@Html.TextBoxFor(m => m.Area, new { @class = "text w_37" })</td>
                                    </tr>
                                    <tr>
                                        <th width="60">地址</th>
                                        <td>@Html.TextBoxFor(m => m.Address, new { @class = "text w_37" })</td>
                                    </tr>
                                    <tr>
                                        <th>移动电话</th>
                                        <td>@Html.TextBoxFor(m => m.Mobile, new { @class = "text w_37" })</td>
                                    </tr>
                                    <tr>
                                        <th width="60">固定电话</th>
                                        <td>@Html.TextBoxFor(m => m.Phone, new { @class = "text w_37" })</td>
                                    </tr>
                                    <tr>
                                        <th>Email</th>
                                        <td>@Html.TextBoxFor(m => m.Email, new { @class = "text w_37" })</td>
                                    </tr>
                                    <tr>
                                        <th>QQ</th>
                                        <td>@Html.TextBoxFor(m => m.QQ, new { @class = "text w_37" })</td>
                                    </tr>
                                    <tr>
                                        <th>头像</th>
                                        <td>
                                            <input type="hidden" name="Avatar" value="@Model.Avatar"/>
                                            <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'user/avatar\'}',multi:false,method:'add',type:'image'}">
                                                    <span class="ico ico_upload_image"></span>
                                                </li>
                                            </ul>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>性别</th>
                                        <td>
                                            @foreach (var gender in @ViewBag.GenderList)
                                            {
                                                if (Model.Gender == @gender.Value)
                                                {
                                                    <label>
                                                        <input class="radio" type="radio" checked="" name="gender" value="@gender.Value" />@gender.Key</label>
                                                }
                                                else
                                                {
                                                    <label>
                                                        <input class="radio" type="radio"  name="gender" value="@gender.Value" />@gender.Key</label>
                                                }
                                            }
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>角色</th>
                                        <td>
                                            <div class="slt js-select" name="Role.Id" wd="264" swd="220">
                                                <div class="curr"><span></span></div>
                                                <div class="show">
                                                    <ul>
                                                        <li val="0"><a>请选择角色</a></li>
                                                        @foreach (var item in @ViewBag.RoleList)
                                                        {
                                                            if (Model.Role!=null&&Model.Role.Id == @item.Id)
                                                            {
                                                                <li selected="selected" val="@item.Id"><a>@item.Name</a></li>
                                                            }
                                                            else
                                                            {
                                                                <li  val="@item.Id"><a>@item.Name</a></li>
                                                            }
                                                        }
                                                    </ul>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>用户类型</th>
                                        <td>
                                            <div class="slt js-select" name="UserType" wd="264" swd="220">
                                                <div class="curr"><span></span></div>
                                                <div class="show">
                                                    <ul>
                                                        @foreach (var item in @ViewBag.UserTypeList)
                                                        {
                                                            if (Model.UserType == @item.Value)
                                                            {
                                                                <li selected="selected" val="@item.Value"><a>@item.Key</a></li>
                                                            }
                                                            else
                                                            {
                                                                <li  val="@item.Value"><a>@item.Key</a></li>
                                                            }
                                                        }
                                                    </ul>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>用户状态</th>
                                        <td>
                                            <div class="slt js-select" name="IsValid" wd="264" swd="220">
                                                <div class="curr"><span></span></div>
                                                <div class="show">
                                                    <ul>
                                                        @foreach (var item in @ViewBag.UserStatusList)
                                                        {
                                                            if (Model.IsValid == @item.Value)
                                                            {
                                                                <li selected="selected" val="@item.Value"><a>@item.Key</a></li>
                                                            }
                                                            else
                                                            {
                                                                <li  val="@item.Value"><a>@item.Key</a></li>
                                                            }
                                                        }
                                                    </ul>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                     @foreach (var group in ViewBag.ExtendGroupList)
                     {
                        <div class="table_form form_main ">
                            <div class="pl_2 pb_3">
                                <table>
                                    <tbody>
                                        @foreach (UserExtendDomain item in Model.ExtendList.Where(n=>n.GroupId==group.Id).ToList())
                                        {
                                            string fieldValue = item.ExtendValue != null ? item.ExtendValue.Value : string.Empty;
                                            <tr>
                                                <th width="80px">@item.Title：</th>
                                                <td>
                                                    @if (@item.FieldType == NodeEnums.BasicFieldType.TextField) {
                                                        <input class="text w_37" type="text" name="extend.@item.FieldName" value="@fieldValue"/>
                                                        
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.TextArea) {
                                                        <textarea name="extend.@item.FieldName" class="h_8 w_37">@fieldValue</textarea>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.PasswordField) {
                                                        <input name="extend.@item.FieldName" class="text w_37" type="password" value="@fieldValue"/>
                                                        <div class="exp ml_1">@item.Hint</div>
                                       
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.RadioButton) {
                                                        foreach (var e in @item.EntryList) {
                                                        <label class="mr_2">
                                                            <input @(e.EntryValue==fieldValue?"checked=checked":string.Empty) name="extend.@item.FieldName" class="radio" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                        }
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.CheckBox) {
                                                        foreach (var e in @item.EntryList) {
                                                            bool result = ManageHtmlHelper.Contains(fieldValue, e.EntryValue);
                                                        <label class="mr_2">
                                                            <input @(result?"checked=checked":string.Empty)  name="extend.@item.FieldName" class="checkbox" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                            
                                                        <div class="exp ml_1">@item.Hint</div>
                                                        }

                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.SelectBox) {
                                                        <select name="extend.@item.FieldName" style="width:382px">
                                                            @foreach (var e in @item.EntryList) {
                                                                <option @(e.EntryValue==fieldValue?"selected=selected":string.Empty)  value="@e.EntryValue">@e.EntryName</option>
                                                            }

                                                        </select>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.FileField) {
                                                        <input type="hidden" name="extend.@item.FieldName" value="@fieldValue" />
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'user/@item.FieldName\'}',multi:false,method:'add',type:'file'}">
                                                                <span class="ico ico_upload_file"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiFile) {
                                                        <input type="hidden"  name="extend.@item.FieldName" value="@fieldValue"/>
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'user/@item.FieldName\'}',multi:true,method:'add',type:'file'}">
                                                                <span class="ico ico_upload_file"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.ImageField) {
                                                        <input type="hidden" name="extend.@item.FieldName"  value="@fieldValue"/>
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'user/@item.FieldName\'}',multi:false,method:'add',type:'image'}">
                                                                <span class="ico ico_upload_image"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiImage) {
                                                        <input type="hidden" name="extend.@item.FieldName"  value="@fieldValue"/>
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'user/@item.FieldName\'}',multi:true,method:'add',type:'image'}">
                                                                <span class="ico ico_upload_image"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else {
                                                        <textarea name="extend.@item.FieldName" id="@item.FieldName" >@fieldValue</textarea>
                                                        <script type="text/javascript">
                                                            var edit = UE.getEditor('@item.FieldName');
                                                        </script>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    }
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    }
                </div>
                <div class="submitbox p_2 extra_normal">
                    <input type="submit" class="btn_1" value="提    交" />
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('.nav_left_style2').find('li').eq(0).addClass('current');
    });
</script>
